<?php
/**
 * Created by Aliyun ApsaraVideo VoD.
 * User: https://www.aliyun.com/product/vod
 * API document: https://help.aliyun.com/document_detail/98467.html
 */

require_once './VodUploadSDK-PHP_1.0.2/VodUploadSDK-PHP_1.0.2'. DIRECTORY_SEPARATOR . 'voduploadsdk' . DIRECTORY_SEPARATOR . 'Autoloader.php';

date_default_timezone_set('PRC');

// 测试上传本地辅助媒资文件
function testUploadLocalAttachedMedia($accessKeyId, $accessKeySecret, $filePath)
{
	try {
		$uploader = new AliyunVodUploader($accessKeyId, $accessKeySecret);
		$uploadAttachedRequest = new UploadAttachedMediaRequest($filePath, 'watermark',
				'testUploadLocalAttachedMedia via PHP-SDK');
		//$uploadAttachedRequest->setCateId(1000009458);
		$res = $uploader->uploadLocalAttachedMedia($uploadAttachedRequest);
		print_r($res);
	} catch (Exception $e) {
		printf("testUploadLocalAttachedMedia Failed, ErrorMessage: %s\n", $e->getMessage());
	}
	
}

// 测试上传网络辅助媒资文件
function testUploadWebAttachedMedia($accessKeyId, $accessKeySecret, $fileURL)
{
	try {
		$uploader = new AliyunVodUploader($accessKeyId, $accessKeySecret);
		$uploadAttachedRequest = new UploadAttachedMediaRequest($fileURL, 'watermark',
				'testUploadWebAttachedMedia via PHP-SDK');
		//$uploadAttachedRequest->setCateId(1000009458);
		$res = $uploader->uploadWebAttachedMedia($uploadAttachedRequest);
		print_r($res);
	} catch (Exception $e) {
		printf("testUploadWebAttachedMedia Failed, ErrorMessage: %s\n", $e->getMessage());
	}
	
}


####  执行测试代码   ####
$accessKeyId = '<AccessKeyId>';
$accessKeySecret = '<AccessKeySecret>';

//$localFilePath = '/opt/image/test.png';
//$localFilePath = 'd:\Pictures\Camera Roll\u=1195300844,1441035790&fm=72.jpg';
//testUploadLocalAttachedMedia($accessKeyId, $accessKeySecret, $localFilePath);

$webFileURL = 'http://img4.imgtn.bdimg.com/it/u=15517654,544816536&fm=26&gp=0.jpg';
testUploadWebAttachedMedia($accessKeyId, $accessKeySecret, $webFileURL);